from socket import socket, AF_INET, SOCK_DGRAM

def start_client():
    recv_socket = socket(AF_INET, SOCK_DGRAM)#客户端也需要指定为udp

    host = '127.0.0.1'
    port = 9999

    while True:
        send_data = input("客户说：")

        recv_socket.sendto(send_data.encode('utf-8'), (host, port))
        if send_data == "bye":   #发送数据为bye则结束
            break
        recv_data = recv_socket.recv(1024)
        print('客服说：',recv_data.decode('utf-8'))
    recv_socket.close()

if __name__ == '__main__':
    start_client()